package de.slothsoft.commons;

public abstract class AbstractIdentifiable<I> implements Identifiable<I> {

	@Override
	public boolean equals(Object obj) {
		if (obj instanceof Identifiable) {
			Identifiable<?> that = (Identifiable<?>) obj;
			return equals(getId(), that.getId())
					&& equals(getClass(), that.getClass());
		}
		return false;
	}

	private boolean equals(Object o1, Object o2) {
		return o1 == o2 || o1 != null && o1.equals(o2);
	}

	@Override
	public int hashCode() {
		return getId() == null ? 0 : getId().hashCode();
	}
}
